package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.mapper.CouponMapper;
import com.cyzy.pojo.Coupon;
import com.cyzy.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Random;

@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService {

    @Autowired
    private CouponMapper couponMapper;

    @Override
    public int addCoupon(Coupon coupon) {
        return couponMapper.addCoupon(coupon);
    }

    @Override
    public List<Coupon> selectCouponList() {
        LambdaQueryWrapper<Coupon> wrapper = new LambdaQueryWrapper<>();
        wrapper.ne(Coupon::getStatus,"1");

        return couponMapper.selectList(wrapper);
    }

    @Override
    public int deleteCoupons(List<Long> templateIds) {
        LambdaUpdateWrapper<Coupon> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(Coupon::getStatus,1).in(Coupon::getTemplateId,templateIds);
        return couponMapper.update(wrapper);
    }

    @Override
    public int deleteCoupon(int templateId) {
        LambdaUpdateWrapper<Coupon> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(Coupon::getStatus,1).in(Coupon::getTemplateId,templateId);

        return couponMapper.update(wrapper);
    }
}
